package clear;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import sys.wx.c.Path;
import sys.wx.components.imyIni.IMYINI;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.base.food.bean.Food;

/**
 *
 * @author IMY
 */
public class ClearDCFile implements IMYINI {

    @Override
    public void imyINI() {
        List<Food> flist = Dao.selectVast(Food.class);
        Set set = new HashSet();
        int leng = pz.dc.FilePath.DC_BASE_FOOD_IMG.length();
        for (Food f : flist) {
            if (null != f.getFood_img()) {
                set.add(f.getFood_img().substring(leng));
            }
        }
        
        File[] listf = new File(Path.getWebPath() + pz.dc.FilePath.DC_BASE_FOOD_IMG).listFiles();
        if (null != listf) {
            for (File f : listf) {
                if (f.isFile() && !set.contains(f.getName())) {
                    System.out.println("在数据库中，没有对应记录，进行自动删除:" + f.getName());
                    f.delete();
                }
            }
        }
    }
}
